# Contributor: Patrycja Rosa <alpine@ptrcnull.me>
# Maintainer: Patrycja Rosa <alpine@ptrcnull.me>
pkgname=acmed
pkgver=0.20.0
pkgrel=0
pkgdesc="ACME (RFC 8555) client daemon"
url="https://github.com/breard-r/acmed"
# s390x, riscv64: blocked by cargo
arch="all !s390x !riscv64"
license="MIT"
pkgusers="acmed"
pkggroups="acmed"
makedepends="cargo openssl-dev"
subpackages="$pkgname-doc $pkgname-openrc $pkgname-tacd $pkgname-tacd-doc:tacd_doc"
install="acmed.pre-install"
source="https://github.com/breard-r/acmed/archive/refs/tags/v$pkgver/acmed-$pkgver.tar.gz
	Cargo.lock
	acmed.confd
	acmed.initd
	"

prepare() {
	default_prepare
	mv "$srcdir"/Cargo.lock "$builddir"
	cargo fetch --locked
}

build() {
	cargo build --release --frozen
}

check() {
	cargo test --frozen
}

package() {
	install -Dm755 -t "$pkgdir"/usr/bin \
		target/release/acmed \
		target/release/tacd

	install -Dm644 -t "$pkgdir"/etc/acmed \
		acmed/config/*
	install -d -o acmed -g acmed "$pkgdir"/var/lib/acmed

	install -Dm644 -t "$pkgdir"/usr/share/man/man8 \
		man/en/acmed.8
	install -Dm644 -t "$pkgdir"/usr/share/man/man5 \
		man/en/acmed.toml.5

	install -Dm755 "$srcdir"/acmed.initd "$pkgdir"/etc/init.d/acmed
	install -Dm644 "$srcdir"/acmed.confd "$pkgdir"/etc/conf.d/acmed
}

tacd() {
	pkgdesc="Standalone tls-alpn-01 challenge validation server"

	amove /usr/bin/tacd
}

tacd_doc() {
	install -Dm644 -t "$pkgdir"/usr/share/man/man8 \
		"$builddir"/man/en/tacd.8

	default_doc
	pkgdesc="Standalone tls-alpn-01 challenge validation server (documentation)"
	install_if="docs $pkgname-tacd=$pkgver-r$pkgrel"
}

sha512sums="
0d2d079c312217bbe6ea54de68792d8bf108dd1d337a1d4d4d4318049fa999f92e7a4d63086711073da21c1aa033666bc1452a8c5da6519f52ea5a12f55891fc  acmed-0.20.0.tar.gz
3a15f8b2d9385d756f99c768f09379084bcb763cf0efedf32f832f1ba8e20507d937e2302212998a2d5dffbdeba98e7ac1dabc1d38a2ea22c64cbd73881f5495  Cargo.lock
23440890f61045df3fe3acbf1d54548eb0102d3871e536698efb7e6d2a238984a556a4294ad1588b53d79ebb5029c6268f8779634d8bebd0a611898b1c8187ff  acmed.confd
91192fd4a5da625ee6462e61aab991acac8644ec4317ecf289a17b424b93a0c615e74eec1b8b41baa42dc97c2e31846b4df3dfc19b22a504b4f01cb335c71843  acmed.initd
"
